from django.contrib import admin
from .models import (
    Department, Role, Resource, RoleResource, AdminUser,
    Workflow, WorkflowPermission, Position, WorkflowApprovalNode, Task, AuditRecord
)

# Register your models here.
@admin.register(Department)
class DepartmentAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')
    search_fields = ('name',)

@admin.register(Role)
class RoleAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')
    search_fields = ('name',)

@admin.register(Resource)
class ResourceAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'pid', 'url')
    search_fields = ('name', 'url')

@admin.register(AdminUser)
class AdminUserAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'phone', 'role', 'department', 'created_at')
    list_filter = ('role', 'department')
    search_fields = ('name', 'phone')
    date_hierarchy = 'created_at'

@admin.register(Workflow)
class WorkflowAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'description', 'status', 'created_at')
    list_filter = ('status',)
    search_fields = ('name', 'description')
    date_hierarchy = 'created_at'

@admin.register(WorkflowPermission)
class WorkflowPermissionAdmin(admin.ModelAdmin):
    list_display = ('id', 'role_id', 'workflow_id', 'created_at')
    list_filter = ('role_id', 'workflow_id')
    date_hierarchy = 'created_at'

@admin.register(Position)
class PositionAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')
    search_fields = ('name',)

@admin.register(WorkflowApprovalNode)
class WorkflowApprovalNodeAdmin(admin.ModelAdmin):
    list_display = ('id', 'workflow_id', 'position_id', 'level', 'type', 'created_at')
    list_filter = ('workflow_id', 'position_id', 'type')
    search_fields = ('workflow_id__name', 'position_id__name')
    date_hierarchy = 'created_at'

@admin.register(Task)
class TaskAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'workflow_id', 'userid', 'next_audit', 'current_level', 'task_status', 'created_at')
    list_filter = ('workflow_id', 'task_status')
    search_fields = ('name',)
    date_hierarchy = 'created_at'

@admin.register(AuditRecord)
class AuditRecordAdmin(admin.ModelAdmin):
    list_display = ('id', 'task_id', 'audit_user', 'audit_time', 'audit_status', 'level')
    list_filter = ('task_id', 'audit_status')
    search_fields = ('comment',)
    date_hierarchy = 'audit_time'
